import pygame
import random

class Bomb:
    def __init__(self, screen_width, screen_height):
        self.screen_width = screen_width
        self.screen_height = screen_height
        
        self.radius = 25
        self.x = random.randint(self.radius, screen_width - self.radius)
        self.y = screen_height
        self.vel_x = random.uniform(-2, 2)
        self.vel_y = random.uniform(-12, -8)
        self.gravity = 0.25
        
        # 碰撞矩形
        self.rect = pygame.Rect(
            self.x - self.radius,
            self.y - self.radius,
            self.radius * 2,
            self.radius * 2
        )

    def update(self):
        self.vel_y += self.gravity
        self.x += self.vel_x
        self.y += self.vel_y
        self.rect.center = (self.x, self.y)
        
        # 边界反弹
        if self.x - self.radius < 0 or self.x + self.radius > self.screen_width:
            self.vel_x *= -0.8

    def draw(self, screen):
        # 绘制炸弹
        pygame.draw.circle(screen, (50, 50, 50), (int(self.x), int(self.y)), self.radius)
        pygame.draw.circle(screen, (0, 0, 0), (int(self.x), int(self.y)), self.radius - 3)
        pygame.draw.line(screen, (255, 0, 0), 
                         (int(self.x - 10), int(self.y)), 
                         (int(self.x + 10), int(self.y)), 2)
        pygame.draw.line(screen, (255, 0, 0), 
                         (int(self.x), int(self.y - 10)), 
                         (int(self.x), int(self.y + 10)), 2)